package top.ivansong92.example.leetcode.learning.data.struct.array.sort;


import org.junit.Test;

import java.util.Arrays;
import java.util.Random;
import java.util.stream.Collectors;

public class TestSort {
    @Test
    public void testBubble() {
        ArraySort arraySort = new BubbleSort();
        doSort(arraySort);
    }

    @Test
    public void testQuick() {
        ArraySort arraySort = new QuickSort();
        doSort(arraySort);
    }

    @Test
    public void testSelect() {
        ArraySort arraySort = new SelectSort();
        doSort(arraySort);
    }

    @Test
    public void testInsert() {
        ArraySort arraySort = new InsertSort();
        doSort(arraySort);
    }

    @Test
    public void testMerge() {
        ArraySort arraySort = new MergeSort();
        doSort(arraySort);
    }

    @Test
    public void testHeap() {
        ArraySort arraySort = new HeapSort();
        doSort(arraySort);
    }

    private void doSort(ArraySort sort) {
        int[] nums = new int[20];
        Random random = new Random();
        for (int i = 0; i < nums.length; i++) {
            nums[i] = random.nextInt(100);
        }

        System.out.println("beforeSort:" + Arrays.toString(nums));
        System.out.println("[" + sort.getClass().getName() + "] sorting...");
        sort.sort(nums);
        System.out.println("afterSort:" + Arrays.toString(nums));
    }
}
